<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 21/01/2019
 * Time: 17:33
 */

namespace App\Modules\Wallet;


use App\Modules\UCenter\BaseUcenter;
use App\Services\Fund\FundIndex;
use App\Services\User\UserIndex;

class Withdraw extends BaseUcenter
{
    //提现
    public function withdraw()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        $data['user_info'] = $userInfo['res'];
        return FundIndex::Withdraw()->applyDrawwith($data);
    }
    //提现申请列表
    public function withdrawList()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->withdrawList($data);
    }
    //个人冻结资金列表
    public function freezeList()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->freezeList($data);
    }
    //司机和企业的收入统计 今日收入 当月累计收入 总收入 余额 保证金 待收款 罚金
    public function earnings()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        $data['role_ids'] = $userInfo['res']['role_ids'];
        return FundIndex::Withdraw()->earnings($data);
    }

    //司机和企业的待收货运单
    public function dueInWaybills()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        $data['role_ids'] = $userInfo['res']['role_ids'];
        return FundIndex::Withdraw()->dueInWaybills($data);
    }

    //司机的罚单列表
    public function penalty()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->penalty($data);
    }

    //司机 的保证金列表
    public function margin()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->margin($data);
    }

    //货主 冻结中资金 保证金 余额
    public function shipperMoney()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->shipperMoney($data);
    }

    //货主 保证金列表 冻结中资金列表  余额列表
    public function shipperMargin()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->shipperMargin($data);
    }


    //货主 待收货运单
    public function shipperDueIn()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->shipperDueIn($data);
    }

    //车主端七日收入统计 当月收入统计
    public function driverIncomeStatistic()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return FundIndex::Withdraw()->driverIncomeStatistic($data);
    }

//------------------------------------------后台管理------------------------------------------------------------------------------
    //后台提现申请列表（可查用户id）
    public function adminWithdrawList()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        return FundIndex::Withdraw()->adminWithdrawList($data);
    }
    //后台审核提现
    public function auditWithdraw()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return auto_failure($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['review_id'] = $userInfo['res']['id'];
        $data['review_info'] = $userInfo['res'];
        return FundIndex::Withdraw()->auditWithdraw($data);
    }

}
